package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysOperateLog;
import io.mybatis.example.springboot.service.SysOperateLogService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_operate_log - 操作日志记录
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysOperateLogs")
public class SysOperateLogController {

  @Autowired
  private SysOperateLogService sysOperateLogService;

  @PostMapping
  public DataResponse<SysOperateLogDO> save(@RequestBody SysOperateLogDO sysOperateLog) {
    return DataResponse.ok(sysOperateLogService.save( sysOperateLog));
  }

  @GetMapping
  public RowsResponse<SysOperateLogDO> findList(@RequestBody SysOperateLogDO sysOperateLog) {
    return RowsResponse.ok(sysOperateLogService.findList( sysOperateLog));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysOperateLogDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysOperateLogService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysOperateLogDO> update(@PathVariable("id") Long id, @RequestBody SysOperateLogDO sysOperateLog) {
    sysOperateLog.setId(id);
    return DataResponse.ok(sysOperateLogService.update( sysOperateLog));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysOperateLogService.deleteById(id) == 1);
  }

}
